import { BaseProgressBar } from "./BaseProgressBar";
import { ImagesConst } from "../../resource/ImagesConst";
import { LayerManager } from "../../manager/LayerManager";
import { FrameTimer } from "../../../../com/gengine/core/frame/FrameTimer";
import { Global } from "../../../../com/gengine/global/Global";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { ProcessType } from "../../rules/ProcessType";
type int = number;
//class SkillProgress
    
    export  class SkillProgress extends BaseProgressBar
    {
        constructor()
        {
            super(ImagesConst.MountProgressBarBg);
            this.progressBarClass = ImagesConst.MountProgressBar;
            this.setValue(50, 100);
            this.setProgressPosition(30, 26);
            this.setLabelPosition(0, 4);
            this.addChildAt(_progressBar, 0);
            showProgressText = false;
            this._parent = LayerManager.popupLayer;
            this._timer = new FrameTimer();
            this.mouseChildren = false;
            this.mouseEnabled = false;
            return;
        }

        public updateData(arg1: int, arg2: string, arg3: int, arg4: Function=null, arg5: int=0, arg6: Function=null, arg7: int=0): void
        {
            this.dispose();
            this._targetId = arg7;
            this._type = arg1;
            this._repeat = Math.ceil(arg3 / Global.stage.frameRate);
            this._callBack = arg4;
            this._interval = Math.ceil(arg5 / Global.stage.frameRate);
            this._interCall = arg6;
            setText(arg2);
            setValue(0, arg3);
            this.addToStage(this._parent);
            this.resize(Global.stage.stageWidth, Global.stage.stageHeight * 3 / 2 - 70);
            this._timer.delay = 1;
            this._timer.repeatCount = this._repeat;
            this._timer.addListener(TimerType.ENTERFRAME, this.onUpdateProgress);
            this._timer.addListener(TimerType.COMPLETE, this.onCompleteProgress);
            this._timer.start();
            return;
        }

        public SkillProgress.get processValue(): number
        {
            if (this._timer && this._timer.running) 
            {
                return this._timer.currentCount / this._repeat;
            }
            return 1;
        }

        /* internal  */onUpdateProgress(arg1: FrameTimer): void
        {
            setValue(arg1.currentCount, this._repeat);
            if (!(this._interval == 0) && arg1.currentCount % this._interval == 0) 
            {
                if (this._interCall != null) 
                {
                    this._interCall();
                }
            }
            return;
        }

        /* internal  */onCompleteProgress(arg1: FrameTimer): void
        {
            if (this._callBack != null) 
            {
                this._callBack();
            }
            this.removeFromStage();
            this.dispose();
            return;
        }

        public SkillProgress.get running(): Boolean
        {
            return this._timer.running && !(this.parent == null);
        }

        public SkillProgress.get isSkillRunning(): Boolean
        {
            return this.running && this.type == ProcessType.Skill;
        }

        public SkillProgress.get type(): int
        {
            return this._type;
        }

        public SkillProgress.get targetId(): int
        {
            return this._targetId;
        }

        public set parentLayer(arg1: Object /* flash.display.DisplayObjectContainer */)
        {
            if (arg1 == this._parent) 
            {
                return;
            }
            this._parent = arg1;
            return;
        }

        public addToStage(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            if (arg1 == this.parent) 
            {
                return;
            }
            if (this.parent != null) 
            {
                this.parent.removeChild(this);
            }
            arg1.addChild(this);
            this._parent = arg1;
            this.resize(Global.stage.stageWidth, Global.stage.stageHeight * 3 / 2 - 20);
            return;
        }

        public removeFromStage(): void
        {
            if (parent != null) 
            {
                parent.removeChild(this);
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this.removeFromStage();
            this._type = 0;
            this._targetId = 0;
            this._timer.stop();
            this._timer.dispose();
            this._timer.isDelete = false;
            this._callBack = null;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            _label.x = 20;
            _label.y = -3;
            return;
        }

        public /* override */ set progressBarClass(arg1: string)
        {
            super.progressBarClass = arg1;
            var loc1=0;
            var loc2=0;
            if (_progressBarBg) 
            {
                loc1 = _progressBarBg.width > _width ? _progressBarBg.width : _width;
                loc2 = _progressBarBg.height > _progressBar.height ? _progressBarBg.height : _progressBar.height;
            }
            else 
            {
                loc1 = _width;
                loc2 = _progressBar.height;
            }
            _label.width = loc1;
            return;
        }

        public /* override */ resize(arg1: number, arg2: number): void
        {
            this.x = (arg1 - 210) / 2;
            this.y = (arg2 - this.height) / 2;
            return;
        }

        public static get instance(): SkillProgress
        {
            if (!SkillProgress._instance) 
            {
                SkillProgress._instance = new SkillProgress();
            }
            return SkillProgress._instance;
        }

        protected /* var */_targetId: int;

        protected /* var */_type: int;

        protected /* var */_timer: FrameTimer;

        protected /* var */_repeat: int;

        protected /* var */_callBack: Function;

        protected /* var */_interval: int;

        protected /* var */_interCall: Function;

        protected /* var */_parent: Object /* flash.display.DisplayObjectContainer */;

        protected static /* var */_instance: SkillProgress;
    }
